<include file="Public/header" />
<title></title>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="form-article-add">
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账册编码：</label>
            <div class="formControls col-xs-8 col-sm-9"><span class="select-box">
				<select name="zccode" data-toggle="<{$result.zccode}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.name}>" placeholder=""  name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>类目：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="category" data-toggle="<{$result.category}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>HSCODE：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.hs_code}>" placeholder="" name="hs_code">
            </div>
        </div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>条形码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.sn}>" placeholder="" name="sn">
            </div>
        </div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品编码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.goods_no}>" placeholder="" name="goods_no">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>第一单位：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="unit" data-toggle="<{$result.unit}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
        </div>
        <!-- <div class="row cl"> -->
            <!-- <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>第一单位数量：</label> -->
            <!-- <div class="formControls col-xs-8 col-sm-9"> -->
                <!-- <input type="text" class="input-text" value="<{$result.count}>" placeholder="" name="count"> -->
            <!-- </div> -->
        <!-- </div> -->
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>第一单位规格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.standard}>" placeholder="" name="standard">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>第一单位价格(单价)：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.price}>" placeholder="" name="price">
            </div>
        </div>
		<!-- <div class="row cl"> -->
            <!-- <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>销售价：</label> -->
            <!-- <div class="formControls col-xs-8 col-sm-9"> -->
                <!-- <input type="text" class="input-text" value="<{$result.sell_price}>" placeholder="" name="sell_price"> -->
            <!-- </div> -->
        <!-- </div> -->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">第二单位：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="unit_t" data-toggle="<{$result.unit_t}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
        </div>
        <!-- <div class="row cl"> -->
            <!-- <label class="form-label col-xs-4 col-sm-2">第二单位数量：</label> -->
            <!-- <div class="formControls col-xs-8 col-sm-9"> -->
                <!-- <input type="text" class="input-text" value="<{$result.count_t}>" placeholder="" name="count_t"> -->
            <!-- </div> -->
        <!-- </div> -->
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">第二单位规格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.unit_t_goods_spec}>" placeholder="" name="unit_t_goods_spec">
            </div>
        </div>
        <!-- <div class="row cl"> -->
            <!-- <label class="form-label col-xs-4 col-sm-2">第二单位价格：</label> -->
            <!-- <div class="formControls col-xs-8 col-sm-9"> -->
                <!-- <input type="text" class="input-text" value="<{$result.price_t}>" placeholder="" name="price_t"> -->
            <!-- </div> -->
        <!-- </div> -->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产销国：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="country" data-toggle="<{$result.country}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
            <!-- <div class="formControls col-xs-8 col-sm-9"> -->
                <!-- <input type="text" class="input-text" value="<{$result.country}>" placeholder="" name="country"> -->
            <!-- </div> -->
        </div>
        <div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>料号（PN）：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.pn}>" placeholder="" name="pn">
            </div>
        </div>
        <div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>料件性质：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.item_type}>" placeholder="" name="item_type">
            </div>
        </div>
		<div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>项号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.item_no}>" placeholder="" name="item_no">
            </div>
        </div>
		<div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>净重：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.net_weight}>" placeholder="" name="net_weight">
            </div>
        </div>
		<div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>毛重：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.gross_weight}>" placeholder="" name="gross_weight">
            </div>
        </div>
		<div class="row cl" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>税率：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.goods_tax}>" placeholder="" name="goods_tax">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>币制：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="currency" data-toggle="<{$result.currency}>" class="select">
                    <option value="0">---请选择---</option>
                </select>
				</span>
            </div>
        </div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品类型：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="goods_cate"  class="select">
					<if condition="$result.goods_cate eq 1">
					<option value="1">一般商品</option>
					</if>
					<if condition="$result.goods_cate eq 2">
					<option value="2">原料</option>
					</if>
					<if condition="$result.goods_cate eq 3">
					<option value="3">辅料</option>
					</if>
					</option>
					<option value="1">一般商品</option>
					<option value="2">原料</option>
					<option value="3">辅料</option>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="save('<{$result.id}>')" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
                <button onClick="cancel()" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
<include file="Public/footer_js" />
<script>
	$(function(){
		$('select[name=zccode]').change(function(){
			type=$(this).find('option:selected').attr('attr_type');
			if(type=='1'){//一般账册
				$('input[name=hs_code]').parent().parent().hide();
				$('input[name=pn]').parent().parent().hide();
				$('input[name=item_type]').parent().parent().hide();
				$('input[name=item_no]').parent().parent().hide();
				$('input[name=net_weight]').parent().parent().hide();
				$('input[name=gross_weight]').parent().parent().hide();
				$('input[name=goods_tax]').parent().parent().hide();
				$('select[name=currency]').parent().parent().parent().hide();
				$('select[name=country]').parent().parent().parent().hide();
			}else{//保税/直邮
				$('input[name=hs_code]').parent().parent().show();
				$('input[name=pn]').parent().parent().show();
				$('input[name=item_type]').parent().parent().show();
				$('input[name=item_no]').parent().parent().show();
				$('input[name=net_weight]').parent().parent().show();
				$('input[name=gross_weight]').parent().parent().show();
				$('input[name=goods_tax]').parent().parent().show();
				$('select[name=currency]').parent().parent().parent().show();
				$('select[name=country]').parent().parent().parent().show();
			}
		})
	})
    function save(id){
		var unit_t_goods_spec=parseInt($("input[name=unit_t_goods_spec]").val());
		<!-- console.log(typeof(unit_t_goods_spec)); -->
        var un=$("select[name=unit]").val();
        un=un.split('-');
        var un_t=$("select[name=unit_t]").val();
        un_t=un_t.split('-');
        if(!un_t[1]){
            un_t=['',''];
        }
        if(!un[1]){
            layer.msg('请选择第一单位');
            return false;
        }
		pn=$("input[name=pn]").val();
		type=$('select[name=zccode]').find('option:selected').attr('attr_type');
        $.post('__CONTROLLER__/editD',{
            id:id,
			pro_status:type,//商品属性
            name:$("input[name=name]").val(),
			item_type:$("input[name=item_type]").val(),
			item_no:$("input[name=item_no]").val(),
            zccode:$("select[name=zccode]").val(),
            <!-- hs_code:$("input[name=hs_code]").val(), -->
            unit:un[1],
            unit_no:un[0],
            price:$("input[name=price]").val(),
			<!-- sell_price:$("input[name=sell_price]").val(), -->
            unit_t:un_t[1],
            unit_no_t:un_t[0],
            category:$("select[name=category]").val(),
            <!-- count:$("input[name=count]").val(), -->
            <!-- count_t:$("input[name=count_t]").val(), -->
            hs_code:$("input[name=hs_code]").val(),
            sn:$("input[name=sn]").val(),
			goods_no:$("input[name=goods_no]").val(),
            country:$("select[name=country]").val(),
            pn:pn,
			goods_tax:$("input[name=goods_tax]").val(),
            standard:$("input[name=standard]").val(),
			unit_t_goods_spec:unit_t_goods_spec,
            currency:$("select[name=currency]").val(),
			net_weight:$("input[name=net_weight]").val(),
			gross_weight:$("input[name=gross_weight]").val(),
			goods_cate:$("select[name=goods_cate]").val(),
        },function (msg){
            layer.msg(msg.data);
            if(msg.flag==1){
                setTimeout(function (){
                    parent.layer.closeAll();
                    parent.location.reload();
                },800);
            }
        },'json');
    }
    function cancel(){
        parent.layer.closeAll();
    }
    ////////获取账册编码
    $.get('__MODULE__/Product/getBook',{},function (msg){
        if(msg.flag==1) {
            getBook(msg.data);
        }
    },'json');
    function getBook(data){
		for(i=0;i<data.length;i++){
				if(data[i]['type']==1){
					type='(一般账册)';
				}else{
					type='(跨境账册)';
				}
				if(data[i]['book_no']==$("select[name=zccode]").attr('data-toggle')){
                    var html='<option attr_type="'+data[i]['type']+'" selected value="'+data[i]['book_no']+'">'+data[i]['book_no']+type+'</option>';
					if(data[i]['type']==1){
						$('input[name=hs_code]').parent().parent().hide();
						$('input[name=pn]').parent().parent().hide();
						$('input[name=item_type]').parent().parent().hide();
						$('input[name=item_no]').parent().parent().hide();
						$('input[name=net_weight]').parent().parent().hide();
						$('input[name=gross_weight]').parent().parent().hide();
						$('input[name=goods_tax]').parent().parent().hide();
						$('select[name=currency]').parent().parent().parent().hide();
						$('select[name=country]').parent().parent().parent().hide();
					}
                }else{
                    var html='<option attr_type="'+data[i]['type']+'" value="'+data[i]['book_no']+'">'+data[i]['book_no']+type+'</option>';
                }
                $("select[name=zccode]").append($(html));
            
        }
    }
    ////////获取类目
    $.get('__MODULE__/Category/getCategory',{},function (msg){
        if(msg.flag==1) {
            getCategory(msg.data, '');
        }
    },'json');
    function getCategory(data,tag){
        for(var m in data){
            if(data[m]['name']){
                if($("select[name=category]").attr('data-toggle')==data[m]['name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                var html='<option '+sel+' value="'+data[m]['name']+'">'+tag+'├'+data[m]['name']+'</option>';
                $("select[name=category]").append($(html));
                if(data[m]['child']){
                    getCategory(data[m]['child'],tag+'&nbsp;&nbsp;')
                }
            }
        }
    }
    ////////获取单位
    $.get('__MODULE__/Unit/getUnit',{},function (msg){
        if(msg.flag==1) {
            getUnit(msg.data);
        }
    },'json');
    function getUnit(data){
        for(var m in data){
            if(data[m]['unit_name']){
                if($("select[name=unit]").attr('data-toggle')==data[m]['unit_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                var html='<option '+sel+' value="'+data[m]['unit_no']+'-'+data[m]['unit_name']+'">'+data[m]['unit_name']+'</option>';
                $("select[name=unit]").append($(html));
                if($("select[name=unit_t]").attr('data-toggle')==data[m]['unit_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                var html='<option '+sel+' value="'+data[m]['unit_no']+'-'+data[m]['unit_name']+'">'+data[m]['unit_name']+'</option>';
                $("select[name=unit_t]").append($(html));
            }
        }
    }
	//获取币制
    $.get('__MODULE__/Unit/getCoin',{},function (msg){
        if(msg.flag==1) {
            getCoin(msg.data);
        }
    },'json');
    function getCoin(data){
        for(var m in data){
            if(data[m]['coin_name']){
                if($("select[name=currency]").attr('data-toggle')==data[m]['coin_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                var html='<option '+sel+' value="'+data[m]['coin_code']+'-'+data[m]['coin_name']+'">'+data[m]['coin_name']+'</option>';
                $("select[name=currency]").append($(html));
                if($("select[name=currency]").attr('data-toggle')==data[m]['coin_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                <!-- var html='<option '+sel+' value="'+data[m]['coin_code']+'-'+data[m]['coin_name']+'">'+data[m]['coin_name']+'</option>'; -->
                <!-- $("select[name=currency]").append($(html)); -->
            }
        }
    }
	//获取国家
    $.get('__MODULE__/Unit/getCountry',{},function (msg){
        if(msg.flag==1) {
            getCountry(msg.data);
        }
    },'json');
    function getCountry(data){
        for(var m in data){
            if(data[m]['country_name']){
                if($("select[name=country]").attr('data-toggle')==data[m]['country_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                var html='<option '+sel+' value="'+data[m]['country_code']+'-'+data[m]['country_name']+'">'+data[m]['country_name']+'</option>';
                $("select[name=country]").append($(html));
                if($("select[name=country]").attr('data-toggle')==data[m]['country_name']){
                    var sel="selected";
                }else{
                    var sel='';
                }
                <!-- var html='<option '+sel+' value="'+data[m]['country_code']+'-'+data[m]['country_name']+'">'+data[m]['country_name']+'</option>'; -->
                <!-- $("select[name=country]").append($(html)); -->
            }
        }
    }
</script>
</body>
</html>